#ifndef _T_GL_SCENE_GRAPH_H_
#define _T_GL_SCENE_GRAPH_H_

#include "../interface/T_gl_Asset.h"
#include "../interface/C_gl_Actor.h"
#include "../interface/I_SceneGraph.h"
#include "../interface/C_Light.h"

class C_gl_SceneGraph : public I_SceneGraph
{
	friend class I_Actor;
private:
	C_gl_Asset	*	m_pShared;

	I_Buffer		*	m_pTriangles;
	I_Buffer		*	m_pCompressedTriangles;

	C_LightManager_GL m_LightManager;

	int m_nFaceCount;

public:                                                      
	C_gl_SceneGraph(void)
	{ 
		m_pShared = NULL; 
		m_pTriangles = NULL; 
		m_pCompressedTriangles = NULL;
	}

	C_gl_SceneGraph(I_api_Device * pDevice)
	{ 
		m_pDevice = pDevice; 
		m_pCommon = NULL;
		m_pShared = NULL; 
		m_pTriangles = NULL; 
		m_pCompressedTriangles = NULL;
	}
	C_gl_SceneGraph(I_api_Device * pDevice, I_api_Common * pCommon)
	{ 
		m_pDevice = pDevice; 
		m_pCommon = pCommon;
		m_pShared = NULL; 
		m_pTriangles = NULL; 
		m_pCompressedTriangles = NULL;
	}
	virtual				~C_gl_SceneGraph(void);

	virtual int	FaceCount() { return m_nFaceCount; }

	virtual bool Deserialize(char * pFileName);
	virtual bool Serialize(char * pFileName);

	virtual void Build(int nType);

	virtual void Compress();

	virtual bool processElement(const char *elementName, 
															NxI32 argc, const char **argv, 
															const char *elementData, NxI32 lineno);

	virtual void Render(C_Camera * pCamera);
	virtual void RenderBVHTree(C_Camera * pCamera, int nMaxLevel, bool bAsset = true, bool bActor = true);

	virtual void	RenderBVHTreeRayTrace(C_Camera * pCamera, 
																			float3 orig, 
																			float3 dir, 
																			int maxLevel, 
																			bool empty);

	virtual	void	TraceIndexedInstanced(I_Buffer * pOrig,
																			I_Buffer * pDir,
																			I_Buffer * pDepth,
																			I_Buffer * pAsset,
																			I_Buffer * pPrimitive,
																			I_Buffer * pColor,
																			bool			 cu = true);

	virtual	void	TraceInstanced(I_Buffer * pOrig,
		I_Buffer * pDir,
		I_Buffer * pDepth,
		I_Buffer * pAsset,
		I_Buffer * pPrimitive,
		I_Buffer * pColor,
		bool			 cu = true);

	virtual	void	TraceIndexedInstanced(float3 RayO, float3 RayD, int RayI,
		I_Buffer * pDepth,
		I_Buffer * pAsset,
		I_Buffer * pPrimitive,
		I_Buffer * pColor);

	virtual	void	TraceIndexed(I_Buffer * pOrig,
														I_Buffer * pDir,
														I_Buffer * pDepth,
														I_Buffer * pAsset,
														I_Buffer * pPrimitive,
														I_Buffer * pColor);


	virtual	void	TraceIndexed(float3 RayO, float3 RayD, int RayI,
														I_Buffer * pDepth,
														I_Buffer * pAsset,
														I_Buffer * pPrimitive,
														I_Buffer * pColor);

	virtual	void Shade(I_api_ShaderResourceView * pDiffuse, I_api_ShaderResourceView * pWorldPos, I_api_ShaderResourceView * pWorldNormal);
};

#endif // _T_GL_SCENE_GRAPH_H_